Conditions | 1 |
Paths | 1 |
Total Lines | 127 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var assert = require('chai').assert, |
||
4 | describe('PlaceDescription', function(){ |
||
5 | |||
6 | it('Create plain', function(){ |
||
7 | assert.instanceOf(GedcomX.PlaceDescription(), GedcomX.PlaceDescription, 'An instance of PlaceDescription is not returned when calling the constructor with new.'); |
||
8 | assert.instanceOf(GedcomX.PlaceDescription(), GedcomX.PlaceDescription, 'An instance of PlaceDescription is not returned when calling the constructor without new.'); |
||
9 | }); |
||
10 | |||
11 | it('Create with JSON', function(){ |
||
12 | var place = GedcomX.PlaceDescription({ |
||
13 | names : [ |
||
14 | { |
||
15 | lang : 'en', |
||
16 | value : 'Pope\'s Creek, Westmoreland, Virginia, United States' |
||
17 | } |
||
18 | ], |
||
19 | type : 'http://identifier/for/the/place/type', |
||
20 | place : { resource : 'http://place' }, |
||
21 | jurisdiction : { resource : 'http://jurisdiction' }, |
||
22 | latitude : 27.9883575, |
||
23 | longitude : 86.9252014, |
||
24 | temporalDescription : { |
||
25 | formal: '+1899-01-04' |
||
26 | }, |
||
27 | spatialDescription : { |
||
28 | resource : 'http://uri/for/KML/document' |
||
29 | } |
||
30 | }); |
||
31 | assert.equal(place.getNames().length, 1); |
||
32 | assert.equal(place.getNames()[0].getLang(), 'en'); |
||
33 | assert.equal(place.getNames()[0].getValue(), 'Pope\'s Creek, Westmoreland, Virginia, United States'); |
||
34 | assert.equal(place.getType(), 'http://identifier/for/the/place/type'); |
||
35 | assert.equal(place.getPlace().getResource(), 'http://place'); |
||
36 | assert.equal(place.getJurisdiction().getResource(), 'http://jurisdiction'); |
||
37 | assert.equal(place.getLatitude(), 27.9883575); |
||
38 | assert.equal(place.getLongitude(), 86.9252014); |
||
39 | assert.equal(place.getTemporalDescription().getFormal(), '+1899-01-04'); |
||
40 | assert.equal(place.getSpatialDescription().getResource(), 'http://uri/for/KML/document'); |
||
41 | }); |
||
42 | |||
43 | it('Create with mixed data', function(){ |
||
44 | var place = GedcomX.PlaceDescription({ |
||
45 | names : [ |
||
46 | GedcomX.TextValue({ |
||
47 | lang : 'en', |
||
48 | value : 'Pope\'s Creek, Westmoreland, Virginia, United States' |
||
49 | }) |
||
50 | ], |
||
51 | type : 'http://identifier/for/the/place/type', |
||
52 | place : GedcomX.ResourceReference({ resource : 'http://place' }), |
||
53 | jurisdiction : GedcomX.ResourceReference({ resource : 'http://jurisdiction' }), |
||
54 | latitude : 27.9883575, |
||
55 | longitude : 86.9252014, |
||
56 | temporalDescription : GedcomX.Date({ |
||
57 | formal: '+1899-01-04' |
||
58 | }), |
||
59 | spatialDescription : GedcomX.ResourceReference({ |
||
60 | resource : 'http://uri/for/KML/document' |
||
61 | }) |
||
62 | }); |
||
63 | assert.equal(place.getNames().length, 1); |
||
64 | assert.equal(place.getNames()[0].getLang(), 'en'); |
||
65 | assert.equal(place.getNames()[0].getValue(), 'Pope\'s Creek, Westmoreland, Virginia, United States'); |
||
66 | assert.equal(place.getType(), 'http://identifier/for/the/place/type'); |
||
67 | assert.equal(place.getPlace().getResource(), 'http://place'); |
||
68 | assert.equal(place.getJurisdiction().getResource(), 'http://jurisdiction'); |
||
69 | assert.equal(place.getLatitude(), 27.9883575); |
||
70 | assert.equal(place.getLongitude(), 86.9252014); |
||
71 | assert.equal(place.getTemporalDescription().getFormal(), '+1899-01-04'); |
||
72 | assert.equal(place.getSpatialDescription().getResource(), 'http://uri/for/KML/document'); |
||
73 | }); |
||
74 | |||
75 | it('Build', function(){ |
||
76 | var place = GedcomX.PlaceDescription() |
||
77 | .addName(GedcomX.TextValue().setLang('en').setValue('Pope\'s Creek, Westmoreland, Virginia, United States')) |
||
78 | .setType('http://identifier/for/the/place/type') |
||
79 | .setPlace(GedcomX.ResourceReference({ resource : 'http://place' })) |
||
80 | .setJurisdiction(GedcomX.ResourceReference({ resource : 'http://jurisdiction' })) |
||
81 | .setLatitude(27.9883575) |
||
82 | .setLongitude(86.9252014) |
||
83 | .setTemporalDescription(GedcomX.Date({ |
||
84 | formal: '+1899-01-04' |
||
85 | })) |
||
86 | .setSpatialDescription(GedcomX.ResourceReference({ |
||
87 | resource : 'http://uri/for/KML/document' |
||
88 | })); |
||
89 | assert.equal(place.getNames().length, 1); |
||
90 | assert.equal(place.getNames()[0].getLang(), 'en'); |
||
91 | assert.equal(place.getNames()[0].getValue(), 'Pope\'s Creek, Westmoreland, Virginia, United States'); |
||
92 | assert.equal(place.getType(), 'http://identifier/for/the/place/type'); |
||
93 | assert.equal(place.getPlace().getResource(), 'http://place'); |
||
94 | assert.equal(place.getJurisdiction().getResource(), 'http://jurisdiction'); |
||
95 | assert.equal(place.getLatitude(), 27.9883575); |
||
96 | assert.equal(place.getLongitude(), 86.9252014); |
||
97 | assert.equal(place.getTemporalDescription().getFormal(), '+1899-01-04'); |
||
98 | assert.equal(place.getSpatialDescription().getResource(), 'http://uri/for/KML/document'); |
||
99 | }); |
||
100 | |||
101 | it('toJSON', function(){ |
||
102 | var data = { |
||
103 | names : [ |
||
104 | { |
||
105 | lang : 'en', |
||
106 | value : 'Pope\'s Creek, Westmoreland, Virginia, United States' |
||
107 | } |
||
108 | ], |
||
109 | type : 'http://identifier/for/the/place/type', |
||
110 | place : { resource : 'http://place' }, |
||
111 | jurisdiction : { resource : 'http://jurisdiction' }, |
||
112 | latitude : 27.9883575, |
||
113 | longitude : 86.9252014, |
||
114 | temporalDescription : { |
||
115 | formal: '+1899-01-04' |
||
116 | }, |
||
117 | spatialDescription : { |
||
118 | resource : 'http://uri/for/KML/document' |
||
119 | } |
||
120 | }, place = GedcomX.PlaceDescription(data); |
||
121 | assert.deepEqual(place.toJSON(), data); |
||
122 | }); |
||
123 | |||
124 | it('constructor does not copy instances', function(){ |
||
125 | var obj1 = GedcomX.PlaceDescription(); |
||
126 | var obj2 = GedcomX.PlaceDescription(obj1); |
||
127 | assert.strictEqual(obj1, obj2); |
||
128 | }); |
||
129 | |||
130 | }); |